<!DOCTYPE html>
<html class="x-admin-sm">
<html lang="en" xmlns:th="http://wwww.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../aaa/css/font.css">
    <link rel="stylesheet" href="../aaa/css/xadmin.css">
    <script src="../aaa/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../aaa/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<script>

    function xmTanUploadImg(obj) {
        var file = obj.files[0];
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {    //成功读取文件
            var img = document.getElementById("selectImg");
            img.src = e.target.result;   //或 img.src = this.result / e.target == this

        };
    }
</script>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" th:action="@{/need/update}" method="post" id="fm" enctype="multipart/form-data">
            <div class="layui-form-item">
                <input type="text" id="needId" name="needId" style="display: none" th:value="${need.needId}">
                <label class="layui-form-label">
                    <span class="x-red">*</span>项目名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="needName" name="needName" required="required" lay-verify="required"
                           autocomplete="off" class="layui-input" th:value="${need.needName}">
                </div>
                <label class="layui-form-label">
                    <span class="x-red">*</span>图片
                </label>
                <div class="layui-input-inline">
                    <img th:src="@{${need.needimg}}" alt="" id="selectImg" style="width: 80px;height: 80px">
                    <input type="file" id="uploadImg" name="img" onchange="xmTanUploadImg(this)">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>日期
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="needtime" class="layui-input" id="test1" placeholder="请选择日期" lay-verify="required" lay-key="1" th:value="${need.needtimeJs}">
                </div>
                <label class="layui-form-label">
                    <span class="x-red">*</span>负责人
                </label>
                <div class="layui-input-inline">
                    <select name="saadminid" class="layui-input" >
                        <option value="0">请选择</option>
                        <option
                                th:each="a:${emp}"
                                th:selected="${a.emp_id eq need.saadminid}"
                                th:value="${a.emp_id}"
                                th:text="${a.emp_name}">
                        </option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>分销商
                </label>
                <div class="layui-input-inline">
                    <select name="BsupId" class="layui-input" >
                        <option value="0">请选择</option>
                        <option
                                th:each="a:${dis}"
                                th:selected="${a.BsupId eq need.BsupId}"
                                th:value="${a.BsupId}"
                                th:text="${a.BsupName}">

                        </option>
                    </select>
                </div>
                <label class="layui-form-label">
                    <span class="x-red">*</span>审核状态
                </label>
                <div class="layui-input-inline">
                    <select name="statusid" class="layui-input-inline">
                        <option value="0">请选择</option>
                        <option
                                th:each="a:${status}"
                                th:selected="${a.statusid eq need.statusid}"
                                th:value="${a.statusid}"
                                th:text="${a.statusname}">
                        </option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <center>
                    <button class="layui-btn layui-btn-radius" lay-filter="add" lay-submit="" style="width: 200px">
                        修改
                    </button>
                </center>
            </div>
        </form>
    </div>
</div>
<script src="../lib/layui/layui.js" charset="utf-8"></script>
<script>

    layui.use(['form', 'layer','jquery'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            //监听提交
            form.on('submit(add)',
                function(data) {
                    var formData = new FormData($("#fm")[0]);
                    console.log(data.field);
                    var saveLoading = parent.layer.msg('数据提交中，请稍后',{icon:16,time:false,shade:0.8});
                    $.ajax({
                        url: "/need/update",
                        type: "POST",
                        data:formData,
                        cache:false,
                        contentType:false,
                        processData:false,
                        success: function (result) {
                            if (result.code==200){
                                layer.msg("修改失败");
                            }
                            else {
                                layer.msg("修改成功",{
                                    icon: 6,
                                    time:500
                                },function() {
                                    parent.window.location.reload();//重新页面
                                    // 获得frame索引
                                    var index = parent.layer.getFrameIndex(window.name);
                                    //关闭当前frame
                                    parent.layer.close(index);
                                });
                            }
                        }, error:function (e) {
                            //返回500错误 或者其他 http状态码错误时 需要在error 回调函数中处理了 并且返回的数据还不能直接alert，需要使用
                            //$.parseJSON 进行转译    res.msg 是自己组装的错误信息通用变量
                            var res = $.parseJSON(e.responseText);
                            layer.msg("修改失败,检查数据填输是否完整");
                        }
                    });
                    return false;
                });
        });
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#test1' //指定元素
        });
    });
</script>
</body>

</html>
